package news;

import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import utils.MyHtmlClient;
import utils.ParserUtil;

public class NewsImport {
	
	private String cookievalue;

	public NewsImport(String cookievalue) {
		this.cookievalue = cookievalue;
	}
	
	public ArrayList<News> GetNews(String url){
		
		ArrayList<News> news = new ArrayList<News>();
			
		MyHtmlClient htmlClient = new MyHtmlClient();
		String htmlString = htmlClient.getHtmlString(url, cookievalue, null);

		String regex = "<td width=\"60\" class=\"line[0..1]\">(.*?)</td>.*?<td width=\"90\" class=\"line[0..1]\">(.*?)</td>.*?<td class=\"line[0..1]\">(.*?)</td>";

		for (Matcher m = Pattern.compile(regex).matcher(ParserUtil.htmlEncoding(
				ParserUtil.cleanHtml(htmlString))); m.find();)
			news.add(new News(m.toMatchResult().group(1), m.toMatchResult()
					.group(2), ParserUtil.cleanMessage(m.toMatchResult().group(3))));
		
		return news;	
	}
}
